<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var weChatEventDataGrid;
    $(function() {
        weChatEventDataGrid = $('#weChatEventDataGrid').datagrid({
        url : '${path}/admin/weChatEvent/dataGrid',
        striped : true,
        rownumbers : true,
        pagination : true,
        idField : 'id',
        sortName : 'id',
        sortOrder : 'desc',
        pageSize : 20,
        pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
        frozenColumns : [ [
            {
                width : '50',
                title : '多选',
                field:'ck',
                checkbox:true 
            }
			,{
           	 	width : '80',
           	 	title : 'id',
           	 	field : 'id',
           	 	sortable : true,

			}
			,{
           	 	width : '250',
           	 	title : 'openId',
           	 	field : 'openId',
           	 	sortable : true,

			}
			,{
           	 	width : '150',
           	 	title : '发生时间',
           	 	field : 'time',
           	 	sortable : true,

			}
			,{
           	 	width : '150',
           	 	title : '类型',
           	 	field : 'type',
           	 	sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                        case 'text':
                            return '文本消息';
                        case 'image':
                            return '图片消息';
                        case 'voice':
                            return '语音消息';
                        case 'video':
                            return '视频消息';
                        case 'shortvideo':
                            return '小视频消息';
                        case 'location':
                            return '地理位置消息';
                        case 'link':
                            return '链接消息';
                        case 'subscribe':
                            return '关注事件';
                        case 'unsubscribe':
                            return '取消关注事件';
                        case 'SCAN':
                            return '扫码事件';
                        case 'LOCATION':
                            return '上报地理位置事件';
                        case 'CLICK':
                            return '自定义菜单CLICK事件';
                        case 'VIEW':
                            return '自定义菜单VIEW事件';
                    }
                }

			},{
                width : '400',
                title : '内容',
                field : 'data',
                sortable : true,

            }
			,{
            field : 'action',
            title : '操作',
            width : 80,
            formatter : function(value, row, index) {
                var str = '';
                <%--<shiro:hasPermission name="/admin/weChatEvent/edit">--%>
                    <%--str += $.formatString('<a href="javascript:void(0)" class="weChatEvent-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="weChatEventEditFun(\'{0}\');" >编辑</a>', row.id);--%>
                <%--</shiro:hasPermission>--%>
                str += $.formatString('<a href="javascript:void(0)" class="weChatEvent-easyui-linkbutton-look" data-options="plain:true,iconCls:\'fi-eye icon-yellow\'" onclick="weChatEventLookFun(\'{0}\');" >查看</a>', row.id);

                return str;
            }
        	}
          ] ],
        singleSelect: false,
        selectOnCheck: true,
        checkOnSelect: true,
        onLoadSuccess:function(data){
            if(data){
                $.each(data.rows, function(index, item){
                    if(item.checked){
                        $('#contentDataGrid').datagrid('checkRow', index);
                    }
                });
            }
            $('.weChatEvent-easyui-linkbutton-edit').linkbutton({text:'编辑'});
            $('.weChatEvent-easyui-linkbutton-look').linkbutton({text:'查看'});

        },
        toolbar : '#weChatEventToolbar'
    });
});

/**
 * 查看
 */
function weChatEventLookFun(id) {
    parent.$.modalDialog({
        title : '编辑',
        width : "60%",
        height : "80%",
        href :  '${path}/admin/weChatEvent/LookPage?id=' + id,
    });
}

/**
 * 添加框
 * @param url
 */
function weChatEventAddFun() {
    parent.$.modalDialog({
        title : '添加',
        width : "60%",
        height : "80%",
        href : '${path}/admin/weChatEvent/addPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = weChatEventDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#weChatEventAddForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 编辑
 */
function weChatEventEditFun(id) {
    if (id == undefined) {
        var rows = weChatEventDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        weChatEventDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '编辑',
        width : "60%",
        height : "80%",
        href :  '${path}/admin/weChatEvent/editPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = weChatEventDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#weChatEventEditForm');
                f.submit();
            }
        } ]
    });
}


<%--/**--%>
 <%--* 删除--%>
 <%--*/--%>
 <%--function weChatEventDeleteFun(id) {--%>
     <%--if (id == undefined) {//点击右键菜单才会触发这个--%>
         <%--var rows = weChatEventDataGrid.datagrid('getSelections');--%>
         <%--id = rows[0].id;--%>
     <%--} else {//点击操作里面的删除图标会触发这个--%>
         <%--weChatEventDataGrid.datagrid('unselectAll').datagrid('uncheckAll');--%>
     <%--}--%>
     <%--parent.$.messager.confirm('询问', '您是否要删除当前数据？', function(b) {--%>
         <%--if (b) {--%>
             <%--progressLoad();--%>
             <%--$.post('${path}/admin/weChatEvent/delete', {--%>
                 <%--id : id--%>
             <%--}, function(result) {--%>
                 <%--if (result.success) {--%>
                     <%--parent.$.messager.alert('提示', result.msg, 'info');--%>
                     <%--weChatEventDataGrid.datagrid('reload');--%>
                 <%--}--%>
                 <%--progressClose();--%>
             <%--}, 'JSON');--%>
         <%--}--%>
     <%--});--%>
<%--}--%>

/**
 * 批量删除
 */
function weChatEventDeleteIdsFun(){
	var ids = getweChatEventSelectionsIds();
 	if(ids.length == 0){
 		$.messager.alert('提示','未选中数据!');
 		return ;
 	}
 	$.messager.confirm('确认','确定删除ID为 '+ids+' 的记录,共'+ids.split(",").length+'记录吗？',function(r){
 	    if (r){
 	    	var params = {"ids":ids};
         	$.post("${path}/admin/weChatEvent/deleteIds",params, function(result){
         		result=JSON.parse(result);
     			if(result.success){
     				parent.$.messager.alert('提示', result.msg, 'info');
                    weChatEventDataGrid.datagrid('reload');
     			}else{
     				$.messager.alert('错误提示',data.msg);
     			}
     		});
 	    }
 	});
}
/**
 * 获得选中的记录
 */
function getweChatEventSelectionsIds(){
	var itemList = $("#weChatEventDataGrid");
	var sels = itemList.datagrid("getSelections");
	var ids = [];
	for(var i in sels){
		ids.push(sels[i].id);
	}
	ids = ids.join(",");
	sels.length=0;
	return ids;
}

/**
 * 清除
 */
function weChatEventCleanFun() {
    $('#weChatEventSearchForm input').val('');
    weChatEventDataGrid.datagrid('load', {});
}
/**
 * 搜索
 */
function weChatEventSearchFun() {
     weChatEventDataGrid.datagrid('load', $.serializeObject($('#weChatEventSearchForm')));
}
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'north',border:false" class="lay_box" style="height: 30px; overflow: hidden;background-color: #fff">
        <form id="weChatEventSearchForm">
            <div class="tab_box">
                <div class="tab_a">
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="weChatEventSearchFun();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="weChatEventCleanFun();">清空</a>
                </div>
                <ul class="list">
					<li>
                        <label>openId:</label>
                        <input name="openId" type="text" placeholder="请输入openId" class="easyui-textbox" data-options="height:29,width:250"/>
                    </li>
					<li>
                        <label>类型:</label>
                        <input name="type" type="text" placeholder="请输入类型" class="easyui-textbox" data-options="height:29,width:200"/>
                    </li>
                </ul>
            </div>
        </form>
     </div>
 
    <div data-options="region:'center',border:false">
        <table id="weChatEventDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="weChatEventToolbar" style="display: none;">
    <shiro:hasPermission name="/admin/weChatEvent/add">
        <a onclick="weChatEventAddFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-page-add'">添加</a>
    </shiro:hasPermission>
        <shiro:hasPermission name="/admin/weChatEvent/deleteIds">
        <a onclick="weChatEventDeleteIdsFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-x icon-red'">删除</a>
    </shiro:hasPermission>
</div>